def flow_statistic_test():
    with open("/Users/daidongyang/tmp/flow-statistic/shandongnewera/flow-sta.log", "r") as file:
        lines = file.readlines()
        # print(old)
    for line in lines:
        string_array = line.split(" ")
        if len(string_array) != 8:
            print(line, '=====================')
        else:
            # 2022-04-06 12:36:33 120.24.144.233:http http 21B 617B 16B 486B
            time = string_array[0] + " " + string_array[1]
            ip = string_array[2]
            if 'http' == string_array[3]:
                port = '80'
            else:
                port = string_array[3]
            print("('" + time + "','" + ip + "'," + port, end='')
            for i in range(4, 8):
                string_item = string_array[i]
                if 'KB' in string_item:
                    unit = 'KB'
                    value = float(string_item.split(unit)[0]) * 1024
                elif 'MB' in string_item:
                    unit = 'MB'
                    value = float(string_item.split(unit)[0]) * 1024 * 1024
                elif 'GB' in string_item:
                    unit = 'GB'
                    value = float(string_item.split(unit)[0]) * 1024 * 1024 * 1024
                elif 'B' in string_item:
                    unit = 'B'
                    value = string_item.split(unit)[0]
                else:
                    print("------------error")
                print(", " + str(value), end='')
            print("),")



if __name__ == '__main__':
    flow_statistic_test()